<template>
    <div class="mineBg">
        <!-- <HeadNav :title="'今日填报'"></HeadNav> -->
        <div class="content">
            <div class="userImg">
                <div class="imgBg"><img
                        src="https://17lelife-bucket.oss-cn-beijing.aliyuncs.com/WeChat-App-Picture/my/info.png" alt=""
                        v-if="isShow">
                    <div class="userRoleText">{{ userInfo.principal }}</div>
                </div>
                <div class="userInfo">
                    <div class="userInfo-name" v-if="userInfo.username !== userInfo.phone">{{ userInfo.username }}</div>
                    <div class="userInfo-tel">{{ userInfo.phone }}</div>
                </div>
            </div>
            <div class="contentTop">
                <van-cell-group :border="false">
                    <van-cell size="large" title="角色" :value="userRole" :border="false"
                        :is-link="(userRole.indexOf('入库') > -1 || userRole.indexOf('出库') > -1)" :to="(userRole.indexOf('入库') > -1 || userRole.indexOf('出库') > -1)? '/userRole' : ''">
                        <template #icon>
                            <img src="../../assets/images/userRole.png" alt="" style="width: 18px; height: 14px;">
                        </template>
                    </van-cell>
                    <van-cell size="large" title="归属" :value="userInfo.belong" :border="false"
                        v-if="userInfo.userType === 'stall' || userInfo.userType === 'supplier'">
                        <template #icon>
                            <img src="../../assets/images/userDangkou.png" alt="" style="width: 16px; height: 16px;">
                        </template>
                    </van-cell>
                    <van-cell size="large" title="修改密码" is-link to="/password">
                        <template #icon>
                            <img src="../../assets/images/editPassWord.png" alt="" style="width: 16px; height: 16px;">
                        </template>
                    </van-cell>
                    <!-- <div class="cellItem">
            <van-field
              v-model="password"
              label="修改密码"
              placeholder="输入新密码"
              input-align="right"
              type="number"
              @blur="onBlur"
            >
              <template #left-icon>
                <img
                  src="../../assets/images/editPassWord.png"
                  alt=""
                  style="width: 16px; height: 16px;">
              </template>
            </van-field>
          </div> -->
                </van-cell-group>
            </div>
            <div class="btnArea">
                <van-button type="primary" class="loginBtn" @click="logout()">退出登录 </van-button>
            </div>
        </div>
        <foot></foot>
    </div>
</template>

<script>
/* eslint-disable */
import { personInfoApi } from '@/api/user'
import { resetPwdApi, logoutApi } from '@/api/api'
import { getParams } from '@/common/public'
// import HeadNav from '@/components/HeadNav'
import foot from '../foot/foot.vue'
import { Toast } from 'vant';
// import moment from 'moment'
// import { mapState } from 'vuex'
export default {
    name: 'MineInfo',
    components: {
        // HeadNav,
        foot
    },
    computed: {
        // ...mapState({
        //     token: (state) => state.applyrecords.token
        // })
    },
    watch: {
        active(newVal) {
            console.log('newVal', newVal)
            if (newVal === 0) {
                this.params.applyType = null
                this.loading = true
                this.contentData = []
                this.finished = false
                if (!this.finished) {
                    this.onLoad(1)
                }
            } else if (newVal === 0) {
                this.params.applyType = newVal
                this.loading = true
                this.contentData = []
                this.finished = false
                if (!this.finished) {
                    this.onLoad(1)
                }
            } else {

            }
        }
    },
    data() {
        return {
            active: 2,
            userRole: '',
            userRoleText: '',
            userInfo: {},
            isShow: false,
            password: undefined
        }
    },
    mounted() {
        // // window.onPageFinished = this.onPageFinished
        // // this.$bridge.registerhandler('onPageFinished')
        // // Android端
        // // window.android.showToast('展示内容提示')
        // // window['onPageFinished'] = (data) => {

        // const u = navigator.userAgent
        // const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1 // g
        // const isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) // ios终端
        // if (isAndroid) {
        //     window.android.hideToolbar()
        //     window.android.setEnableSwipeBack(true)
        // }
        // if (isIOS) {
        //     var s = {}
        //     this.$bridge.callhandler('hideToolbar', s, (data) => { })
        // }
        // // }
        console.log(777, localStorage.getItem('currentType'),typeof(localStorage.getItem('currentType')))

         if (localStorage.getItem('currentType') === 'stall') {
            this.userRole = '档口工作人员'
            this.userRoleText = '档口'
        }else if (localStorage.getItem('currentType') === 'supplier') {
            this.userRole = '供应商工作人员'
            this.userRoleText = '供应商'
        } else if (localStorage.getItem('currentType') === 'logistics_out') {
            this.userRole = '出库工作人员'
            this.userRoleText = '出库'
        } else if (localStorage.getItem('currentType') === 'logistics_in') {
            this.userRole = '入库工作人员'
            this.userRoleText = '入库'
        } 

    },
    created() {
        const accessToken = localStorage.getItem('access_token')
        if (!accessToken) {
            this.$router.push('/login')
        }
        this.personInfoMethod()
        // // 保存token
        // // localStorage.setItem('Authorization', '')
        // const Authorization = getParams('access_token')
        // this.$store.commit('applyrecords/setToken', Authorization)
        // // this.$store.state.area.areaSelect
        // console.log(
        //     'this.$store.state.applyrecords.token',
        //     this.$store.state.applyrecords.token
        // )
        // console.log(Authorization)
        // console.log(location.href)
        // localStorage.setItem('Authorization', Authorization)
        // if (!sessionStorage.getItem('Authorization')) {
        //     sessionStorage.setItem('Authorization', Authorization)
        // }

        // console.log(sessionStorage.getItem('Authorization'))
        // // 认证任务
        // // this.getApplyRecordPho()
        // // 获取认证类型
        // this.paramsStatus.access_token = sessionStorage.getItem('Authorization')
        // getVerifyTypeList(this.paramsStatus).then((res) => {
        //     if (res.statusCode === 0) {
        //         console.log('获取认证类型', res)
        //         const list = res.content.map((item, index) => {
        //             return {
        //                 typeId: item.typeId,
        //                 typeName: item.typeName
        //             }
        //         })
        //         console.log('list', list)
        //         if (list.length > 0) {
        //             this.tabDatasss = this.tabDatasss.concat(list)
        //             this.tabData = this.tabDatasss
        //             console.log('tabData1', this.tabData)
        //         }
        //         // this.tabData = this.tabData.concat(list)
        //         console.log('tabData2', this.tabData)
        //     } else {
        //         // this.$message.error(res.errorMessage)
        //     }
        // })
    },
    methods: {
        
        // 退出登录
        logout() {
            logoutApi().then(res => {
                console.log(res, 'res')
                if (res.code == 200) {
                    this.$router.push({ path: '/login' })
                    // 清除所有 localStorage 数据
                    localStorage.clear();
                    console.log('LocalStorage 数据已全部清除');
                }
            })
        },
        personInfoMethod() {
            personInfoApi().then(res => {
                console.log(res, 'userInfo')
                if (res.code === 200) {
                    const userData = res.data
                    if (res.data.currentType) {
                        if (userData.currentType == 'stall') {
                            this.userRole = '档口工作人员'
                            this.userRoleText = '档口'
                        } else if (userData.currentType == 'logistics_in') {
                            this.userRole = '入库工作人员'
                            this.userRoleText = '入库'
                        } else if (userData.currentType == 'logistics_out') {
                            this.userRole = '出库工作人员'
                            this.userRoleText = '出库'
                        } else if (userData.currentType == 'supplier') {
                            this.userRole = '供应商工作人员'
                            this.userRoleText = '供应商'
                        }
                    }
                    this.userInfo = res.data
                }
            })
        },
        onBlur(e) {
            console.log(e, 'e', this.password)
            if (this.password) {
                resetPwdApi({ password: this.password }).then(res => {
                    if (res.code === 200) {
                        Toast('修改密码成功！')
                    }
                    console.log(res, 'res')
                })
            }
        },

    },
    beforeDestroy() {
        console.log('index')
        window.removeEventListener('scroll', this.onLoad, true)
    }
}
</script>

<style lang="less" scoped>
span,
p {
    padding: 0;
    margin: 0;
}

.mineBg {
    background: url(../../assets/images/myBg.png) no-repeat;
    background-size: 100%;
    background-color: white;
    padding-top: 162px;
    padding-bottom: 50px;
}


.content {
    // margin-top: 35px;
    position: relative;
    width: 100%;
    display: flex;
    flex-direction: column;
    // padding-bottom: 50px;
    height: calc(100vh - 50px);
    background: #fff;
    border-radius: 40px 40px 0px 0px;
}

.userImg {
    position: absolute;
    text-align: center;
    top: -62px;
    left: calc((100% - 125px)/2);

    .imgBg {
        display: flex;
        align-items: center;
        flex-direction: column;
        justify-content: center;
        background-color: #F8F8F8;
        width: 125px;
        height: 125px;
        border-radius: 50%;
        position: relative;
    }

    img {
        width: 125px;
        height: 125px;
    }

    .userRoleText {
        // position: absolute;
        // top: 33%;
        // left: 25%;
        font-size: 20px;
        text-align: center;
        color: #000000;
        white-space: normal;
        overflow-wrap: break-word;
        // word-break: break-all;
    }
}

.userInfo {
    margin-top: 12px;

    .userInfo-name {
        color: #000000;
        font-size: 14px;
        line-height: 14px;
    }

    .userInfo-tel {
        color: #666666;
        font-size: 12px;
        line-height: 12px;
        margin-top: 16px;
    }
}

.contentTop {
    padding: 0px 24px;
    margin-top: 171px;
    display: flex;
    align-items: center;
    width: calc(100% - 48px);


    .cellItem {
        height: 50px;
        line-height: 20px;
        display: flex;
        align-items: center;
    }

}

/deep/.van-cell-group {
    background-color: #fff;
    width: 100%;
}

/deep/.van-cell--large .van-cell__title {
    font-size: 14px;
    color: #000000;
    margin-left: 10px;
}

/deep/.van-cell,
.van-cell--large,
.van-cell--clickable {
    height: 60px !important;
    // line-height:50px !important;
    display: flex;
    align-items: center;
}

/*清浮动*/
.clearfix:after {
    content: '';
    display: block;
    clear: both;
}

.clearfix {
    zoom: 1;
}


.emptyContainer {
    height: 50px;

    /deep/.van-list__finished-text {
        height: 400px;
        background: palegreen;
    }
}



.btnArea {
    padding: 0px 30px;
    margin-top: 54px;
    padding-bottom: 50px;
}

.loginBtn {
    width: 100%;
    height: 45px;
    border: none;
    background: #047DCB;
    border-radius: 45px;
    margin-bottom: 20px;
}

/deep/ .van-field__control--right {
    border-bottom: 1px solid #ebedf0 !important;
}

/deep/ .van-field__control {
    border-bottom: 1px solid #ebedf0 !important;
    color: #969799;
}

// 输入框label
/deep/ .van-cell__title,
.van-field__label {
    font-size: 14px;
    color: #000000;
    margin-left: 10px;
}

// 输入框图标
/deep/ .van-field__left-icon {
    margin-right: 0px;
}
</style>